#include "choose_background.h"
#include <QtGui>
#include <QFile>

#include "moc_choose_background.h"

using namespace std;

ChooseBackground::ChooseBackground(QWidget *parent):Choose_background_form(){
	setupUi(this);
	connect(toolButtonAdd, SIGNAL(clicked()), this, SLOT(Add()));
    connect(toolButtonRemove, SIGNAL(clicked()), this, SLOT(Remove()));
    connect(toolButtonExit, SIGNAL(clicked()), this, SLOT(Exit()));

}

ChooseBackground::~ChooseBackground(){}
/*
    This file is part of Slydini.

    Slydini is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Slydini is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Slydini.  If not, see <http://www.gnu.org/licenses/>.
*/

void ChooseBackground::RefreshView(){
     iconView_2->clear();
     iconView_2->setMaxItemWidth(160);        
     QDir dir2(QString("gui/images2/"), "*.jpg");
     for (unsigned int i = 0; i < dir2.count(); i++) {
         picture_2 = new QPixmap(QString::fromUtf8("gui/images2/") + dir2[i]);
         (void) new Q3IconViewItem( iconView_2, dir2[i], picture_2->scaledToWidth(160) );
         delete picture_2;
         }
     iconView_2->setMaxItemWidth(160);
     }

void ChooseBackground::Add(){
     if ( iconView->currentItem() != 0 ){
        QFile fromFile(QString::fromUtf8("gui/images1/")+iconView->currentItem()->text().toUtf8().constData());
        QFile toFile(QString::fromUtf8("gui/images2/")+iconView->currentItem()->text().toUtf8().constData());   
        fromFile.copy(toFile.fileName());
        RefreshView();
        }
     }
void ChooseBackground::Remove(){
     if ( iconView_2->currentItem() != 0 ){
        QFile toRemove(QString::fromUtf8("gui/images2/")+iconView_2->currentItem()->text().toUtf8().constData());
        toRemove.remove();
        RefreshView();
        }
     }

void ChooseBackground::Exit(){
     close();
     delete(this);
     }
